package game.breeze.gameserver;

import game.breeze.gameserver.controller.GameMapController;
import game.breeze.gameserver.controller.ContainerController;
import game.breeze.gameserver.controller.PlayerController;
import game.breeze.resource.GameMapDef;
import game.breeze.resource.manager.GameResourceManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class World extends ContainerController {
	private static final World instance = new World();
	private Map<Integer, GameMapController> gameMaps = new ConcurrentHashMap<Integer, GameMapController>();
	private long lastUpdateFrameTime;

	public static final World getInstance() {
		return instance;
	}

	private World() {
	}

	public void init(GameResourceManager resManager) {
		for (GameMapDef mapDef : resManager.getMapResourceManager().getMapDictionary().values()) {
			gameMaps.put(mapDef.getId(), new GameMapController(mapDef));
		}
	}

	public void update() {
		float delta = (System.nanoTime() - lastUpdateFrameTime) / 1000000000.0f;
		lastUpdateFrameTime = System.nanoTime();
		update(delta);
	}

	public GameMapController getMapController(int id) {
		return gameMaps.get(id);
	}

	@Override
	public void update(float delta) {
		for (GameMapController map : gameMaps.values()) {
//			map.update(delta);
		}
	}

	@Override
	public void onControllerAdded(PlayerController controller) {

	}
}
